package com.sinodata.bsm.center.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.sinodata.bsm.center.dao.BaseDao;
import com.sinodata.bsm.center.dao.NotifyDao;
import com.sinodata.bsm.common.vo.Notify;

/**
 * <p>
 * Description: 事件通知DAO实现类
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-6-5 PM 2:32:51      liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Repository
public class NotifyDaoImpl extends BaseDao implements NotifyDao {

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.dao.NotifyDao#findByEvent(java.lang.Long)
     */
    @Override
    @SuppressWarnings("unchecked")
    public List<Notify> findByEvent(Long eventId) {
        String hql = "from Notify t where t.eventId=:eventId";
        Query query = this.getSession().createQuery(hql.toString()).setParameter("eventId", eventId);
        return query.list();
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<Notify> findByNotifyRuleId(Long notifyRuleId) {
        String hql = "from Notify t where t.notifyRuleId=" + notifyRuleId;
        Query query = this.getSession().createQuery(hql.toString());
        return query.list();
    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.dao.NotifyDao#findByEvent(java.lang.Long[])
     */
    @Override
    @SuppressWarnings("unchecked")
    public List<Notify> findByEvent(Long[] eventIds) {
        String hql = "from Notify t where t.eventId in(:eventIds)";
        Query query = this.getSession().createQuery(hql.toString()).setParameterList("eventIds", eventIds);
        return query.list();
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.dao.NotifyDao#batchDelete()
     */
    @Override
    public void batchDelete(Long[] ids) {
        if (ids == null || ids.length == 0) {
            return;
        }
        this.getSession().createQuery("delete from Notify where id in (:ids)").setParameterList("ids", ids).executeUpdate();
    }

}
